Technical Field
The invention relates to an electronic device. Particularly, the invention relates to a compass sensor in an electronic device and a heading calibration method thereof.
Related Art
Along with progress of technology, regarding operations and control of an electronic device, besides operations performed by using keyboards or an operation interface displayed on a touch screen, there are also many operation applications generated according to determination of an orientation and a moving state of the electronic device itself or an externally connected remote device (for example, a game device and a control handle thereof), for example, a direction of a racing car in a game executed by the electronic device can be controlled by swaying the electronic device.
Generally, regarding a method for measuring an orientation of an object, an accelerometer and a compass sensor configured in the electronic device can be used to obtain sensing data, and through calculation of an Euler angle or quaternion equation, a current posture and orientation of the electronic device can be obtained. Moreover, a sensor fusion could also be implemented by adding data sensed by a gyroscope sensor configured in the electronic device. The main operation principle of the sensor fusion is that an inclining angle of an object is obtained according to a variation amount of acceleration of gravity detected by the accelerometer, and a horizontal heading angle is obtained according to a magnetic variation (i.e. the aforementioned sensing data) detected by the compass sensor. Thereafter, the aforementioned inclining angle and the horizontal heading angle are synthesized to obtain the current orientation and inclining state of the electronic device.
However, when there is magnetic field interference in the ambient environment, the magnetic variation detected by the compass sensor may cause an error, such that the estimated horizontal heading angle also has an error. Therefore, in order to obtain an accurate horizontal heading angle, a magnetic calibration would be generally executed before the heading angle estimation, so as to eliminate the magnetic field interference.
In the conventional technique, many processing methods can be used to implement the aforementioned magnetic calibration, for example, a center point of a circle is obtained according to a characteristic of a planar circle, and the obtained circle center is a magnetic offset reference value. The method of obtaining the circle center may include averaging a plurality of coordinates corresponding to the data sensed by the compass sensor to serve as the circle center, or averaging coordinates corresponding to a maximum value and a minimum value in the data sensed by the compass sensor to serve as the circle center. However, the magnetic calibration performed according to the characteristic of the planar circle is too simple and inaccurate. A reason thereof is that in an actual environment, the magnetic field has a 3D spatial distribution rather than a planar distribution, so that the magnetic calibration performed according to the characteristic of the planar circle may result in an inaccurate result, and is liable to be influenced by environment variation. Therefore, how to obtain the magnetic offset reference value through a simple method and ensure that the magnetic offset reference value is not easy to be influenced by the magnetic field of the ambient environment to cause error are problems of the field required to be resolved.